import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, OneToMany, ManyToMany, JoinTable } from "typeorm";
import { ApiProperty } from "@nestjs/swagger";

import {BlogEntity} from './../blog/blog.entity'
import { RoleEntity} from './../role/role.entity'

@Entity({name:'tyk_user'})
export class UserEntity{
    @ApiProperty({description:'主键'})
    @PrimaryGeneratedColumn({name:'user_id'})
    userId:number

    @ApiProperty({description:'昵称'})
    @Column({name:'user_name'})
    userName:string

    @ApiProperty({description:'密码'})
    @Column({
        name:'user_pass',
        nullable:true,
        length:20,
        comment:'用户登录密码',
        type:'varchar'
    })
    userPass:string

    @ApiProperty({description:'电话'})
    @Column({name:'user_phone'})
    userPhone:string

    @ApiProperty({description:'邮箱'})
    @Column({name:'user_email'})
    userEmail:string

    @OneToMany(type=>BlogEntity,blog=>blog.user)
    blogs:BlogEntity[]

    @ManyToMany((type)=>RoleEntity,(roles)=>roles.users,)
    @JoinTable({
        name: 'tyk_user_role',
        joinColumns: [
          {name: 'user_id'},
        ],
        inverseJoinColumns: [
          {name: 'role_id'},
        ],
      })
    roles:RoleEntity[]

    @ApiProperty({description:'创建时间'})
    @CreateDateColumn({ type: 'timestamp', name: 'create_date', comment: '创建时间' })
    createDate: Date

    @ApiProperty({description:'更新时间'})
    @UpdateDateColumn({ type: 'timestamp', name: 'update_date', comment: '更新时间' })
    updateDate: Date
}